/* model */
import { BaseSelectUserErrorMessageEnum } from '@src/component/common/BaseSelectUser/model'
import MsgModel from '@model/MsgModel'
/* store */
import {
  useBaseSelectUserStoreFetchLabelList,
  useBaseSelectUserStoreFetchStateList,
  useBaseSelectUserStoreLabelList,
  useBaseSelectUserStoreStateList,
} from '@src/component/common/BaseSelectUser/store'
/* util */
import { message } from '@src/util/message'

/** 
 * @description 获取选人组件 用户状态列表
*/
function useFetchStateList() {
  
  const { setUserStateList } = useBaseSelectUserStoreStateList()
  const fetchStateList = useBaseSelectUserStoreFetchStateList()
  
  const fetchStateListImpl = () => {
    return (
      fetchStateList().then(result => {
        
        if (MsgModel.isSuccess(result)) {
          
          const stateList = result?.data || []
          
          setUserStateList(stateList)
          
        } else {
          message.error(result?.message || BaseSelectUserErrorMessageEnum.StateList)
        }
        
      })
    )
  }
  
  return fetchStateListImpl
}

/** 
 * @description 获取选人组件 人员标签列表
*/
function useFetchLabelList() {
  
  const { setUserLabelList } = useBaseSelectUserStoreLabelList()
  const fetchLabelList = useBaseSelectUserStoreFetchLabelList()
  
  const fetchDepartmentListImpl = () => {
    return (
      fetchLabelList().then(result => {
        
        if (MsgModel.isSuccess(result)) {
          
          const labelList = result?.data || []
          
          setUserLabelList(labelList)
          
        } else {
          message.error(result?.message || BaseSelectUserErrorMessageEnum.LabelList)
        }
        
      })
    )
  }
  
  return fetchDepartmentListImpl
}

export {
  useFetchStateList,
  useFetchLabelList
}